<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Geometry</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Geometry</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/vendor/plugins/attachment_fu/lib/geometry_rb.html">
                vendor/plugins/attachment_fu/lib/geometry.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This <a href="Geometry.html">Geometry</a> class was yanked from RMagick.
However, it lets ImageMagick handle the actual change_geometry. Use <a
href="Geometry.html#M000004">new_dimensions_for</a> to get <a
href="Geometry.html#M000001">new</a> dimensons Used so I can use spiffy
RMagick geometry strings with ImageScience
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000002">from_s</a>&nbsp;&nbsp;
      <a href="#M000001">new</a>&nbsp;&nbsp;
      <a href="#M000004">new_dimensions_for</a>&nbsp;&nbsp;
      <a href="#M000003">to_s</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">FLAGS</td>
          <td>=</td>
          <td class="context-item-value">['', '%', '&lt;', '&gt;']</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
! and @ are removed until support for them is added

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">RFLAGS</td>
          <td>=</td>
          <td class="context-item-value">{ '%' =&gt; :percent,              '!' =&gt; :aspect,              '&lt;' =&gt; :&gt;,              '&gt;' =&gt; :&lt;,              '@' =&gt; :area }</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">RE</td>
          <td>=</td>
          <td class="context-item-value">/\A(\d*)(?:x(\d+))?([-+]\d+)?([-+]\d+)?([%!&lt;&gt;@]?)\Z/</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
Construct an object from a geometry string

</td>
        </tr>
        </table>
      </div>
    </div>



    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">flag</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">height</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">width</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">x</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">y</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">from_s</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/geometry.rb, line 30</span>
30:   <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">from_s</span>(<span class="ruby-identifier">str</span>)
31:     <span class="ruby-identifier">raise</span>(<span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;no geometry string specified&quot;</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">str</span>
32:   
33:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">m</span> = <span class="ruby-constant">RE</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">str</span>)
34:       <span class="ruby-identifier">new</span>(<span class="ruby-identifier">m</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">m</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">m</span>[<span class="ruby-value">3</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">m</span>[<span class="ruby-value">4</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-constant">RFLAGS</span>[<span class="ruby-identifier">m</span>[<span class="ruby-value">5</span>]])
35:     <span class="ruby-keyword kw">else</span>
36:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;invalid geometry format&quot;</span>
37:     <span class="ruby-keyword kw">end</span>
38:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000001" class="method-detail">
        <a name="M000001"></a>

        <div class="method-heading">
          <a href="#M000001" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(width=nil, height=nil, x=nil, y=nil, flag=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000001-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/geometry.rb, line 15</span>
15:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">width</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">height</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">x</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">y</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">flag</span>=<span class="ruby-keyword kw">nil</span>)
16:     <span class="ruby-comment cmt"># Support floating-point width and height arguments so Geometry</span>
17:     <span class="ruby-comment cmt"># objects can be used to specify Image#density= arguments.</span>
18:     <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;width must be &gt;= 0: #{width}&quot;</span>   <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">width</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
19:     <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;height must be &gt;= 0: #{height}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">height</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span>
20:     <span class="ruby-ivar">@width</span>  = <span class="ruby-identifier">width</span>.<span class="ruby-identifier">to_f</span>
21:     <span class="ruby-ivar">@height</span> = <span class="ruby-identifier">height</span>.<span class="ruby-identifier">to_f</span>
22:     <span class="ruby-ivar">@x</span>      = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">to_i</span>
23:     <span class="ruby-ivar">@y</span>      = <span class="ruby-identifier">y</span>.<span class="ruby-identifier">to_i</span>
24:     <span class="ruby-ivar">@flag</span>   = <span class="ruby-identifier">flag</span>
25:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">new_dimensions_for</span><span class="method-args">(orig_width, orig_height)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
attempts to get <a href="Geometry.html#M000001">new</a> dimensions for the
current geometry string given these old dimensions. This doesn&#8216;t
implement the aspect flag (!) or the area flag (@). PDI
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/geometry.rb, line 52</span>
52:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_dimensions_for</span>(<span class="ruby-identifier">orig_width</span>, <span class="ruby-identifier">orig_height</span>)
53:     <span class="ruby-identifier">new_width</span>  = <span class="ruby-identifier">orig_width</span>
54:     <span class="ruby-identifier">new_height</span> = <span class="ruby-identifier">orig_height</span>
55: 
56:     <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@flag</span>
57:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:percent</span>
58:         <span class="ruby-identifier">scale_x</span> = <span class="ruby-ivar">@width</span>.<span class="ruby-identifier">zero?</span>  <span class="ruby-value">? </span><span class="ruby-value">100</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@width</span>
59:         <span class="ruby-identifier">scale_y</span> = <span class="ruby-ivar">@height</span>.<span class="ruby-identifier">zero?</span> <span class="ruby-value">? </span><span class="ruby-ivar">@width</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@height</span>
60:         <span class="ruby-identifier">new_width</span>    = <span class="ruby-identifier">scale_x</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">orig_width</span>.<span class="ruby-identifier">to_f</span>  <span class="ruby-operator">/</span> <span class="ruby-value">100.0</span>)
61:         <span class="ruby-identifier">new_height</span>   = <span class="ruby-identifier">scale_y</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">orig_height</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">100.0</span>)
62:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:&lt;</span>, <span class="ruby-identifier">:&gt;</span>, <span class="ruby-keyword kw">nil</span>
63:         <span class="ruby-identifier">scale_factor</span> =
64:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">new_width</span>.<span class="ruby-identifier">zero?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">new_height</span>.<span class="ruby-identifier">zero?</span>
65:             <span class="ruby-value">1.0</span>
66:           <span class="ruby-keyword kw">else</span>
67:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@width</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@height</span>.<span class="ruby-identifier">nonzero?</span>
68:               [<span class="ruby-ivar">@width</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">new_width</span>.<span class="ruby-identifier">to_f</span>, <span class="ruby-ivar">@height</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">new_height</span>.<span class="ruby-identifier">to_f</span>].<span class="ruby-identifier">min</span>
69:             <span class="ruby-keyword kw">else</span>
70:               <span class="ruby-ivar">@width</span>.<span class="ruby-identifier">nonzero?</span> <span class="ruby-value">? </span>(<span class="ruby-ivar">@width</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">new_width</span>.<span class="ruby-identifier">to_f</span>) <span class="ruby-operator">:</span> (<span class="ruby-ivar">@height</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">new_height</span>.<span class="ruby-identifier">to_f</span>)
71:             <span class="ruby-keyword kw">end</span>
72:           <span class="ruby-keyword kw">end</span>
73:         <span class="ruby-identifier">new_width</span>  = <span class="ruby-identifier">scale_factor</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">new_width</span>.<span class="ruby-identifier">to_f</span>
74:         <span class="ruby-identifier">new_height</span> = <span class="ruby-identifier">scale_factor</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">new_height</span>.<span class="ruby-identifier">to_f</span>
75:         <span class="ruby-identifier">new_width</span>  = <span class="ruby-identifier">orig_width</span>  <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@flag</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">orig_width</span>.<span class="ruby-identifier">send</span>(<span class="ruby-ivar">@flag</span>,  <span class="ruby-identifier">new_width</span>)
76:         <span class="ruby-identifier">new_height</span> = <span class="ruby-identifier">orig_height</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@flag</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">orig_height</span>.<span class="ruby-identifier">send</span>(<span class="ruby-ivar">@flag</span>, <span class="ruby-identifier">new_height</span>)
77:     <span class="ruby-keyword kw">end</span>
78: 
79:     [<span class="ruby-identifier">new_width</span>, <span class="ruby-identifier">new_height</span>].<span class="ruby-identifier">collect!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-identifier">v</span>.<span class="ruby-identifier">round</span> }
80:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">to_s</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert object to a geometry string
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/attachment_fu/lib/geometry.rb, line 41</span>
41:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
42:     <span class="ruby-identifier">str</span> = <span class="ruby-value str">''</span>
43:     <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;%g&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-ivar">@width</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@width</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
44:     <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'x'</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@width</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@height</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
45:     <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;%g&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-ivar">@height</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@height</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
46:     <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;%+d%+d&quot;</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@x</span>, <span class="ruby-ivar">@y</span>] <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@x</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@y</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>)
47:     <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">FLAGS</span>[<span class="ruby-ivar">@flag</span>.<span class="ruby-identifier">to_i</span>]
48:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>